Document title

Subtitle

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut elit odio. Donec fermentum tellus neque, vitae fringilla orci pretium vitae. Fusce maximus finibus facilisis. Donec ut ullamcorper turpis.

Published

January 4, 2022

1 Introduction

1.1 YAML header

In this template many of the Quarto options for HTML output are listed in the YAML header. If you want to know more about these settings I recommend the HTML format reference for a complete list of available options.

Quarto offers also extensive YAML intelligence (completion and diagnostics) in the RStudio IDE and in VS Code for project files, YAML front matter, and executable cell options. Just start with some letters and press the tab key on the keyboard. You will see a small dialog box with a list of available options.

1.2 Code blocks

Code blocks in Quarto documents are treated in similar way as in Markdown documents. One important difference is that code chunk options (in Quarto also called ‘cell level options’) are typically included in special comments using #| at the top of code chunks rather than within the line that begins the chunk:

Show the code
summary(cars)

Please note that individual words are separated with a hyphen, not a dot, followed by a colon, not an equal sign as in R Markdown documents. Quarto uses this approach to both better accommodate longer options like fig-cap, fig-subcap, and fig-alt as well as to make it straightforward to edit chunk options within more structured editors that don’t have an easy way to edit chunk metadata (e.g. most traditional notebook UIs).

However, if you prefer it is still possible to include chunk options on the first line (e.g. ```{r, echo = FALSE}) as in R Markdown documents.

1.3 Callout blocks

Quarto provides five different types of callouts that are an excellent way to draw extra attention to certain concepts.

Note

The color and icon will be different depending upon the type that you select. You can choose between: note, warning, important, tip, and caution.

Tip With Caption

This is an example of a callout with a caption.

This is an example of a ‘folded’ caution callout that can be expanded by the user. You can use collapse="true" to collapse it by default or collapse="false" to make a collapsible callout that is expanded by default.

2 Methods

2.1 Cross-referencing

External images and R figures can be referenced with @fig-label, where ‘label’ is the name of the code chunk. These label names should not contain underscores to separate words, use hyphens here instead. Note that figures need to have a caption to be numbered and for cross-referencing, The caption is also set in the chunk option with #| fig-cap: "Your caption".

Tables require similarly a label and table caption for cross-referencing. But here, the cross-reference contains the prefix ‘tbl’: @tbl-label.

Cross-references to individual sections can simply be made with the prefix ‘sec’ and by adding a ‘{#sec-identifier}’ to any heading.

This is for example a cross-reference to Table 2 in Section 3.2 and a cross-reference to Fig. 6 in Section 3.3.

To create a reference-able code block, add a #lst-identifier along with a lst-cap attribute inside the curly braces (see code chunk example Listing 1). Note that the indication of the programming language requires for this static code block a dot set before the ‘r’.

Listing 1: Example for a referenceable code block

4+4

2.2 Mathjax

A little math formula :

\[x = \sum_{i=1}^{n} \sqrt{\frac{y}{i}} \]

Here is a more complex example where the equation is embedded in a LaTeX equation environment including numbering and crossreferencing:

If the random variable \(Y\) follows a standard normal distribution, i.e. \(Y \sim N(0,1)\), it’s density function can be described with

\[ f_{Y}(y)=\varphi(y) \stackrel{\mathrm{def}}{=} \frac{1}{\sqrt{2 \pi}} \exp \left\{ -\frac{y^2}{2} \right\}, \quad y \in \mathbb{R}. \tag{1}\]

\(\pi\) represents the circle number or Ludolph’s number. The function

\[ F_{Y}(y)=\Phi(y) \stackrel{\mathrm{def}}{=} \int_{-\infty}^y \varphi(x) \,\mathrm{d}x, \quad y \in \mathbb{R} \tag{2}\]

represents then the distribution function of Equation 1.

2.3 Images

Quarto includes several features aimed at making it easier to work with figures and subfigures, as well as for laying out panels that contain multiple figures, tables, or other content.

For instance, if you have several figures that appear as a group, you can create a figure div to enclose them (see Fig. 1 and Fig. 2).

The layout attribute enables the creation of much more complex layouts. Fig. 3 provides an example with a common figure caption and one identifier for all three.

 

 

3 Analysis

3.1 R output

R output is typically shown in the monospace font (here an example with the mtcars dataset in the subfolder data/):

Show the code
# Import dataset from the data/ folder
mtcars <- read.csv("data/mtcars.csv")
summary(mtcars[,1:4])
      mpg             cyl             disp             hp       
 Min.   :10.40   Min.   :4.000   Min.   : 71.1   Min.   : 52.0  
 1st Qu.:15.43   1st Qu.:4.000   1st Qu.:120.8   1st Qu.: 96.5  
 Median :19.20   Median :6.000   Median :196.3   Median :123.0  
 Mean   :20.09   Mean   :6.188   Mean   :230.7   Mean   :146.7  
 3rd Qu.:22.80   3rd Qu.:8.000   3rd Qu.:326.0   3rd Qu.:180.0  
 Max.   :33.90   Max.   :8.000   Max.   :472.0   Max.   :335.0  

3.2 Tables

Here is a simple table based on Markdown Syntax (Table 1).

Table 1: My Caption
A New Table
left-aligned center-aligned right-aligned
$123 $456 $789
italics strikethrough boldface

Here is a sample table output using the knitr::kable() function.

Show the code
tab <- aggregate(. ~ Species, data = iris, mean)
kable(tab)
Table 2: Species-specific mean lengths and widths.
Species Sepal.Length Sepal.Width Petal.Length Petal.Width
setosa 5.006 3.428 1.462 0.246
versicolor 5.936 2.770 4.260 1.326
virginica 6.588 2.974 5.552 2.026

3.3 Figures

A base graphics histogram (Fig. 4).

Show the code
hist(rnorm(100))

Here for comparison a boxplot with a different image height (Fig. 5).

Show the code
boxplot(mpg ~ am, mtcars)

3.4 Tabbed sections

You can create a tabset via a markdown div with the class name panel-tabset. Each top-level heading within the div creates a new tab as shown below:

Show the code
boxplot(rnorm(100), rnorm(100))

Cum eaque dicta architecto culpa eius. Dignissimos officiis error exercitationem. Adipisci odit ad ea iusto fugiat laborum maiores. Dolore sunt et veritatis alias nesciunt maxime cumque. Culpa aut non ea. Culpa ex quia debitis sint eveniet cum.

3.5 Interactive figures with plotly

If the package ‘plotly’ is installed, the following code block will be executed:

Show the code
p <- plotly::plot_ly(data = mtcars, x = ~mpg, y = ~wt, color = ~cyl)
plotly::add_markers(p)

3.6 Diagrams

Quarto has native support for embedding Mermaid and Graphviz diagrams. This enables you to create flowcharts, sequence diagrams, state diagrams, gnatt charts, and more using a plain text syntax inspired by markdown.

3.6.1 Mermaid

Mermaid is a Javascript based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams (see Fig. 9).

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]
  style C fill:#f9f,stroke:#333,stroke-width:4px
  style E fill:#bbf,stroke:#f66,stroke-width:2px,color:#fff,stroke-dasharray: 5 5

Note

Cell level options are here indicated with %%| instead of #|!

sequenceDiagram
  participant Alice
  participant Bob
  Alice->>John: Hello John, how are you?
  loop Healthcheck
    John->>John: Fight against hypochondria
  end
  Note right of John: Rational thoughts 
prevail! John-->>Alice: Great! John->>Bob: How about you? Bob-->>John: Jolly good!

Useful links:

3.6.2 Graphviz

The Graphviz layout programs take descriptions of graphs in a simple text language and make diagrams in useful formats. Graphviz has many useful features for concrete diagrams, such as options for colors, fonts, tabular node layouts, line styles, hyperlinks, and custom shapes (see Fig. 10).

G run run intr intr run–intr kernel kernel run–kernel runbl runbl intr–runbl runbl–run zombie zombie kernel–zombie sleep sleep kernel–sleep runmem runmem kernel–runmem sleep–runmem swap swap sleep–swap runswap runswap swap–runswap runswap–runmem new new runswap–new new–runmem

Note

Cell level options are here indicated with //|!

4 Footnotes

Here is a footnote reference1, and another2.

5 Adding citations and bibliography

Link a .bib document via the YAML header, and the bibliography will be printed at the end. The default bibliography style is provided in the sage-harvard.csl file (do not delete), which adopts the SAGE Harvard reference style.

References can be cited directly within the document using the Quarto equivalent of the citation system [@key], where key is the citation key in the first line of the entry in the .csl file. Example: (Taylor and Green, 1937). To cite multiple entries, separate the keys by semicolons (e.g., (Kamm, 2000; Knupp, 1999). You can also write in-text citations, as follows: Taylor and Green (1937) say this and that.

There is also the package citr which I highly recommend: citr provides functions and an RStudio add-in to search a BibTeX-file to create and insert formatted Markdown citations into the current document. If you are using the reference manager Zotero the add-in can access your reference database directly.

5.1 Software

If you want to include a paragraph on the software used, here is some example text/code to get the current R and package versions. The code to generate a bibliography file including all package references has been already added at the beginning of this script (code chunk ‘generate-package-refs’).

All analyses were performed using the statistical software R (version 4.1.2) (R Core Team, 2021). This report, including tables and figures, was generated using the R packages ‘rmarkdown’ (version 2.14) (Allaire et al., 2022) and ‘knitr’ (version 1.39) (Xie, 2022).

6 References

Allaire J, Xie Y, McPherson J, et al. (2022) Rmarkdown: Dynamic Documents for r. Available at: https://CRAN.R-project.org/package=rmarkdown.
Kamm J (2000) Evaluation of the Sedov-von Neumann-Taylor blast wave solution. Technical Report LA-UR-00-6055. Los Alamos National Laboratory.
Knupp P (1999) Winslow smoothing on two-dimensional unstructured meshes. Eng Comput 15: 263–268.
R Core Team (2021) R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. Available at: https://www.R-project.org/.
Taylor G and Green A (1937) Mechanism of the production of small eddies from large ones. P Roy Soc Lond A Mat 158(895): 499–521.
Xie Y (2022) Knitr: A General-Purpose Package for Dynamic Report Generation in r. Available at: https://yihui.org/knitr/.

Acknowledgments

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut elit odio. Donec fermentum tellus neque, vitae fringilla orci pretium vitae. Fusce maximus finibus facilisis. Donec ut ullamcorper turpis.

Footnotes

  1. Here is the footnote.↩︎

  2. Here’s one with multiple blocks.

    Subsequent paragraphs are indented to show that they belong to the previous footnote.

    { some.code }

    The whole paragraph can be indented, or just the first line. In this way, multi-paragraph footnotes work like multi-paragraph list items.↩︎

Reuse

Citation

BibTeX citation:
@online{name2022,
  author = {Author name},
  title = {Document Title},
  date = {2022-01-04},
  url = {https://example.com/summarizing-output},
  langid = {en}
}
For attribution, please cite this work as:
Author name (2022) Document title. Available at: https://example.com/summarizing-output.